package com.example.timeline;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.example.timeline.checktype.CheckDataItem;
import com.example.timeline.checktype.TypeOneHanlder;
import com.example.timeline.checktype.TypeThreeHandler;
import com.example.timeline.checktype.TypeTwoHanlder;
import com.example.timeline.recycleAdapter.CommonAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    List<CheckDataItem> items;
    List<CommonAdapter.DataHandler<CheckDataItem>> handlers;
    RecyclerView mRecyclerView ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new TimeLine.Builder()
                .addlib(this)
                .addlib(new Level1Libs())
                .addlib(new TimeLine.timeLinePackage() {
                    @TimeLine.TimeLineTick(level = 99,thread = TimeLine.TimeLineTick.FORGROUND)
                    public void fromInterface(TimeLine.RunningMsg msg){
                        Log.d("xtimeline:","fromInterface "+Thread.currentThread()+" "+System.currentTimeMillis());
                    }
                 })
                .run();

        items = new ArrayList<>();
        for(int i=0;i<1500;i++){
            if(i%3 == 0){
                CheckDataItem item = new CheckDataItem();
                item.type="one";
                item.content = "content["+i+"]";
                items.add(item);
            }else if(i%3==1){
                CheckDataItem item = new CheckDataItem();
                item.type="two";
                item.content = "content["+i+"]";
                items.add(item);
            }else{
                CheckDataItem item = new CheckDataItem();
                item.type="three";
                item.content = "content["+i+"]";
                items.add(item);
            }
        }

        handlers = new ArrayList<>();
        handlers.add(new TypeOneHanlder());
        handlers.add(new TypeTwoHanlder());
        handlers.add(new TypeThreeHandler());

        CommonAdapter adapter = new CommonAdapter(items,handlers);
        mRecyclerView = (RecyclerView) findViewById(R.id.typelist);

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        //设置adapter
        mRecyclerView.setAdapter(adapter);
        //设置Item增加、移除动画
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }

    @TimeLine.TimeLineTick(level = 2,thread = TimeLine.TimeLineTick.FORGROUND)
    public void level2for1(TimeLine.RunningMsg msg){
        Log.d("xtimeline:","level2for1 "+Thread.currentThread()+" "+System.currentTimeMillis());
    }

    @TimeLine.TimeLineTick(level = 2,thread = TimeLine.TimeLineTick.BACKGROUND)
    public void level2back1(TimeLine.RunningMsg msg){
        Log.d("xtimeline:","level2back1 "+Thread.currentThread()+" "+System.currentTimeMillis());
    }

    @TimeLine.TimeLineTick(level = 3,thread = TimeLine.TimeLineTick.BACKGROUND)
    public void level3back1(TimeLine.RunningMsg msg){
        Log.d("xtimeline:","level3back1 "+Thread.currentThread()+" "+System.currentTimeMillis());
    }
}
